package com.chujian.system.sys.controller;


import com.chujian.framework.core.base.BaseController;
import com.chujian.framework.core.base.BaseService;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.sys.entity.SysRole;
import com.chujian.sys.entity.SysRoleUser;
import com.chujian.sys.vo.SaveRoleUserVo;
import com.chujian.system.sys.service.SysRoleUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 用户角色表控制层
 *
 * @author chujian
 * @since 2021-08-26
 */
@RequestMapping("/sysRoleUser")
@RestController
@Slf4j
public class SysRoleUserController extends BaseController<SysRoleUser> {

    @Resource
    private SysRoleUserService baseService;

    @Override
    public BaseService<SysRoleUser> getBaseService() {
        return baseService;
    }

    @GetMapping("/listRoleUser")
    public Result<?> listRoleUser(@RequestParam("roleId") Long roleId) {
        return okRs(baseService.listRoleUser(roleId, true));
    }

    @PostMapping("/saveRoleUser")
    public Result<?> saveRoleUser(@RequestBody SaveRoleUserVo roleUserDto) {
        baseService.saveRoleUser(roleUserDto.getRoleId(), roleUserDto.getUserIds());
        return okRs();
    }

    @GetMapping("/getRolesByUserId")
    public Result<?> getRolesByUserId() {
        List<SysRole> roles = baseService.getRolesByUserId();
        return okRs(roles);
    }

}
